﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Simulation
{
	class C_NODE
	{
		F_SETT ST = new F_SETT();

		// [ General Inoformation ] ---------------------------------------------------------------
		public	int		NDID;			// Node ID
		public	int		POSX;			// Position X
		public	int		POSY;			// Posttion Y
		public	int		PRID;			// Parent ID
		public	int		HPCT;			// Hop Count
		public	float	ENGY;			// Node Energy
		public	float	COST;			// Cost from the base station to a node
		public	int		MGCT;			// Message Count
		public	int		CHLD;			// Child Number of Each Node

		// [ SEF ] --------------------------------------------------------------------------------
		public	int		SPID;			// PID of SEF
		public	int[]	KEYS;			// Random Keys of SEF
		public	string	SKEY;			// Keys String			
		public	int		DFRC;			// Defense False Report Count

		// [ LEAP ] -------------------------------------------------------------------------------
		public	int		INDK;			// Individual Key of LEAP
		public	int		PRWK;			// Pairwise Key of LEAP
		public	int		CLSK;			// Clster key of LEAP
		public	int		GRPK;			// Group Key of LEAP
		public	int		DFMC;			// Defense False Message Count

		// [ ATTACK ] -----------------------------------------------------------------------------
		public	bool	CMND;			// Compromised Node (success or failure)
		public	bool	SKND;			// Sinkhole Attack (success or failure)

		// [ LOG ] --------------------------------------------------------------------------------
		public	int		CTFR;			// A Quantity of False Report
		public	int		CTFM;			// A Quantity of Routing Control Message
		public	int		RPER;			// Routing Path Error

		private	int maxx;
		private	int maxy;

		Random R = new Random( ( int )DateTime.Now.Ticks );

		public C_NODE()
		{
			// [ General Inoformation ]
			NDID = -1;
			POSX = -1;
			POSY = -1;
			PRID = -1;
			HPCT = -1;
			ENGY = 0.0f;
			COST = -0.0f;
			MGCT = 0;
			CHLD = 0;

			// [ SEF ]
			SPID = -1;
			KEYS = new int[ST.OKYDS];
			SKEY = null;
			DFRC = 0;

			// [ LEAP ]
			INDK = -1;
			PRWK = -1;
			CLSK = -1;
			GRPK = -1;
			DFMC = 0;

			// [ ATTACK ]
			CMND = false;
			SKND = false;

			// [ RESULT ]
			CTFR = 0;
			CTFM = 0;
			RPER = 0;
		}

		public void SetData( int ndid, int posx, int posy )
		{
			NDID = ndid;
			POSX = posx;
			POSY = posy;
		}

		public void SetSize( int x, int y )
		{
			this.maxx = x;
			this.maxy = y;
		}

		public int RandPosX( int i )
		{
			return R.Next( 1, maxx - 20 );
		}

		public int RandPosY( int i )
		{
			return R.Next( 1, maxy - 20 );
		}

		public float ConsumeEnergyForGeneratingMAC( float E )
		{
			return E + 15f;
		}

		public float ConsumeTransmitting( float E )
		{
			return E + 16.56f;
		}

		public float CunsumeReceiving( float E )
		{
			return E + 12.5f;
		}

		//public int RandPosY( int tmp_y, int pos_y )
		//{
		//    if ( Math.Abs( tmp_y - pos_y ) <= 40 )
		//    {
		//        tmp_y = R.Next( 1, maxx - 20 );
		//        RandPosX( tmp_y, pos_y );
		//    }

		//    return tmp_y;
		//}

		//public int RandPosX( int tmp_x, int pos_x )
		//{
		//    if ( Math.Abs( tmp_x - pos_x ) <= 40 )
		//    {
		//        tmp_x = R.Next( 1, maxx - 20 );
		//        RandPosX( tmp_x, pos_x );
		//    }

		//    return tmp_x;
		//} 

		
	}
}
